// ES2016
// 1. Array.prototype.includes
const arr = ['foo', 1, NaN, false]

// indexOf不能用于查找NaN
console.log(arr.indexOf('foo'))
console.log(arr.indexOf('bar'))
console.log(arr.indexOf(NaN))
console.log(arr.includes('foo'))
console.log(arr.includes('bar'))
console.log(arr.includes(NaN))

// 指数运算符

console.log(Math.pow(2, 10))

console.log(2 ** 20)




// ------------------------------------
// ES2017
console.log('---------------------------------------')
const obj = {
    foo: 'value1',
    bar: 'value2'
}
// - 1. Object.values

console.log(Object.values(obj))

// - 2. Object.entries
console.log(Object.entries(obj))
for(const [key, value] of Object.entries(obj)){
    console.log(key, value)
}
console.log(new Map(Object.entries(obj)))
// - 3. Object.getOwnPropertyDescriptors

const p1 = {
    firstName: 'lei',
    lastName: 'wang',
    get fullName(){
        return this.firstName + ' ' + this.lastName
    }
}
console.log(p1.fullName)

// const p2 = Object.assign({}, p1)
// p2.firstName = 'liuchao'
// console.log(p2.fullName)


const descriptors = Object.getOwnPropertyDescriptors(p1)
console.log(descriptors)
const p2 = Object.defineProperties({}, descriptors)
p2.firstName = 'liuchao'
console.log(p2.fullName)


// - 4. String.prototype.padStart / String.prototype.padEnd

const books = {
    html: 3, 
    css: 15, 
    js: 22
}
// for(const [key, value] of Object.entries(books)){
//     console.log(key, value)
// }
for(const [key, value] of Object.entries(books)){
    console.log(`${key.padEnd(16, '-')}|${value.toString().padStart(3, '0')}`)
}


// - 5. 在函数参数中添加尾逗号

function foo2(bar, baz,) {
    return 100
}

const arr2 = [100,200,300,]


